package 常用类库API;

public class Cat implements Comparable<Cat>,Cloneable
{

	@Override
	//重写接口方法.此方法比较对象，大于返回正整数，等于返回0小于返回负整数
	public int compareTo(Cat p1)
	{
		//按年龄增序排，反向排的话，p1-this的age或-1和1调货位置
		/*
		//第一种写法
		if(this.age<p1.age)return -1;
		if(this.age>p1.age)return 1;
		return 0;
		*/
		//简便写法
		return this.age-p1.age;
	}
	
	private String name;
	private int age;
	
	public Cat(String name,int age){
		this.name=name;
		this.age=age;
	}

	@Override
	public String toString()
	{
		// TODO: Implement this method
		return "Cat[name="+name+",age="+age+"]";
	}

	@Override
	protected Object clone() throws CloneNotSupportedException
	{
		// TODO: Implement this method
		return super.clone();
	}

	
	
	
	
}
